package com.lgc.webtest.configuration.dataSource;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

@Aspect
@Component
@Slf4j
public class DataSourceAop {
//    @Before("execution(* com.shangpin.pay.facade.mapper.payment.*.*.insert*(..)) || execution(* com.shangpin.pay.facade.mapper.payment.*.*.update*(..)) || execution(* com.shangpin.pay.facade.mapper.payment.*.*.delete*(..))")
    public void setPaymentDataSourceType() {
        DBContextHolder.paymentMaster();
        log.info("payment的dataSource切换到：paymentMaster");
    }

//    @Before("execution(* com.shangpin.pay.facade.mapper.payment.*.*.select*(..)) || execution(* com.shangpin.pay.facade.mapper.payment.*.*.count*(..))")
    public void setPaymentReadDataSourceType() {
        DBContextHolder.paymentSlave();
        log.info("payment的dataSource切换到：paymentSlave");
    }

//    @Before("execution(* com.shangpin.pay.facade.mapper.partner.*.*.insert*(..)) || execution(* com.shangpin.pay.facade.mapper.partner.*.*.update*(..)) || execution(* com.shangpin.pay.facade.mapper.partner.*.*.delete*(..))")
    public void setPartnerReadDataSourceType() {
        DBContextHolder.partnerMaster();
        log.info("Partner的DataSource切换到：partnerMaster");
    }

//    @Before("execution(* com.shangpin.pay.facade.mapper.partner.*.*.select*(..)) || execution(* com.shangpin.pay.facade.mapper.partner.*.*.count*(..))")
    public void setPartnerWriteDataSourceType() {
        DBContextHolder.partnerSlave();
        log.info("Partner的DataSource切换到：partnerSlave");
    }
}
